package com.visionet.waveletData.web.repository.business;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.visionet.waveletData.web.entity.business.Relationship;

public interface RelationshipDao extends PagingAndSortingRepository<Relationship, Long>,JpaSpecificationExecutor<Relationship> {
	
	@Query("from Relationship where userId = ?1")
	public List<Relationship> findAllRelationshipByUser(Long userId);
	
	@Query("from Relationship where otherUserId = ?1")
	public List<Relationship> findAllRelationshipByOtherUser(Long userId);
	
	/**
	 * 根据关注人和被管主任查询
	 * @param userId
	 * @param otherUserId
	 * @return
	 */
	@Query("from Relationship where userId = ?1 and otherUserId = ?2")
	public List<Relationship> findOnlyRelationship(Long userId,Long otherUserId);

    @Query("select count(id) from Relationship where userId = ?1")
    public Long findAttentionNum(Long userId);

    @Query("select count(id) from Relationship where otherUserId = ?1")
    public Long findFansNum(Long userId);
}
